<template>
  <el-dialog :visible.sync="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false">
    <el-form ref="dataFormRef" :model="dataForm" :rules="dataRules" label-width="100px" @keyup.enter="submitHandle()">
      <el-row>
        <el-col :span="24">
          <el-form-item label="ID" prop="id">
            <el-input v-model="dataForm.id" placeholder="ID" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="业务主键" prop="businessKey">
            <el-input v-model="dataForm.businessKey" placeholder="业务主键" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="附件ID" prop="attachId">
            <el-input v-model="dataForm.attachId" placeholder="附件ID" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="环境因素识别任务信息ID" prop="targetId">
            <el-input v-model="dataForm.targetId" placeholder="环境因素识别任务信息ID" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="厂房/区域" prop="workshop">
            <el-input v-model="dataForm.workshop" placeholder="厂房/区域" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="子单元（系统/设施）" prop="subUnitSystem">
            <el-input v-model="dataForm.subUnitSystem" placeholder="子单元（系统/设施）" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="子单元（活动）" prop="subUnitAction">
            <el-input v-model="dataForm.subUnitAction" placeholder="子单元（活动）" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="环境因素" prop="envFactor">
            <el-input v-model="dataForm.envFactor" placeholder="环境因素" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="时态" prop="tense">
            <el-input v-model="dataForm.tense" placeholder="时态" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="状态" prop="status">
            <el-input v-model="dataForm.status" placeholder="状态" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="环境影响" prop="evnImpact">
            <el-input v-model="dataForm.evnImpact" placeholder="环境影响" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="是否判断法" prop="judgmentMethodType">
            <el-input v-model="dataForm.judgmentMethodType" placeholder="是否判断法" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="专家评定法" prop="expertJudgment">
            <el-input v-model="dataForm.expertJudgment" placeholder="专家评定法" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="可能性" prop="possibility">
            <el-input v-model="dataForm.possibility" placeholder="可能性" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="严重性" prop="severity">
            <el-input v-model="dataForm.severity" placeholder="严重性" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="管理迫切性" prop="managementUrgency">
            <el-input v-model="dataForm.managementUrgency" placeholder="管理迫切性" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="分值" prop="score">
            <el-input v-model="dataForm.score" placeholder="分值" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="风险度" prop="riskDegree">
            <el-input v-model="dataForm.riskDegree" placeholder="风险度" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="重要环境因素" prop="importantEvnFactor">
            <el-input v-model="dataForm.importantEvnFactor" placeholder="重要环境因素" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="风险策略" prop="riskStrategy">
            <el-input v-model="dataForm.riskStrategy" placeholder="风险策略" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="管理策略" prop="manageStrategy">
            <el-input v-model="dataForm.manageStrategy" placeholder="管理策略" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="识别部门" prop="identifyDepartment">
            <el-input v-model="dataForm.identifyDepartment" placeholder="识别部门" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="识别日期" prop="identifyDate">
            <el-input v-model="dataForm.identifyDate" placeholder="识别日期" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="dataForm.remark" placeholder="备注" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="创建人工号" prop="createdUserCode">
            <el-input v-model="dataForm.createdUserCode" placeholder="创建人工号" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="创建人姓名" prop="createdUserName">
            <el-input v-model="dataForm.createdUserName" placeholder="创建人姓名" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="创建时间" prop="createdTime">
            <el-input v-model="dataForm.createdTime" placeholder="创建时间" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="修改人工号" prop="updatedUserCode">
            <el-input v-model="dataForm.updatedUserCode" placeholder="修改人工号" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="修改人姓名" prop="updatedUserName">
            <el-input v-model="dataForm.updatedUserName" placeholder="修改人姓名" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="修改时间" prop="updatedTime">
            <el-input v-model="dataForm.updatedTime" placeholder="修改时间" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="删除标志" prop="delFlag">
            <el-input v-model="dataForm.delFlag" placeholder="删除标志" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="submitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>

<script>
import { useEnvironmental_factor_identificationApi, useEnvironmental_factor_identificationSubmitApi } from '@/api/business/environmental_factor_identification'

export default {
  name: 'AddOrUpdate',
  data() {
    return {
      visible: false,
      dataForm: {
        id: '',
        businessKey: '',
        attachId: '',
        targetId: '',
        workshop: '',
        subUnitSystem: '',
        subUnitAction: '',
        envFactor: '',
        tense: '',
        status: '',
        evnImpact: '',
        judgmentMethodType: '',
        expertJudgment: '',
        possibility: '',
        severity: '',
        managementUrgency: '',
        score: '',
        riskDegree: '',
        importantEvnFactor: '',
        riskStrategy: '',
        manageStrategy: '',
        identifyDepartment: '',
        identifyDate: '',
        remark: '',
        createdUserCode: '',
        createdUserName: '',
        createdTime: '',
        updatedUserCode: '',
        updatedUserName: '',
        updatedTime: '',
        delFlag: ''
      },
      dataRules: {}
    }
  },
  methods: {
    init(id) {
      this.visible = true
      this.dataForm.id = ''
      const formInstance = this.$refs.dataFormRef
      if (formInstance) {
        formInstance.resetFields()
      }
      if (id) {
        this.getEnvironmental_factor_identification(id)
      }
    },
    getEnvironmental_factor_identification(id) {
      useEnvironmental_factor_identificationApi(id).then(res => {
        Object.assign(this.dataForm, res.data)
      })
    },
    submitHandle() {
      this.$refs.dataFormRef.validate((valid) => {
        if (!valid) {
          return false
        }
        useEnvironmental_factor_identificationSubmitApi(this.dataForm).then(() => {
          this.$message.success({
            message: '操作成功',
            duration: 500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        })
      })
    }
  }
}
</script>
